package com.mrduan.otgfilemanager.common;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.mrduan.otgfilemanager.R;
import com.mrduan.otgfilemanager.utils.SuanFa;
import com.shike.baselibrary.activity.BaseActivity;

import java.io.IOException;

public class ShareActivity extends BaseActivity {

    private TextView duihuan;

    @Override
    public int getContentView() {
        return R.layout.activity_share;
    }

    @Override
    public void initBindWidget() {

        duihuan = getView(R.id.duihuan);
    }


    @Override
    public void initListener() {
        duihuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                inputTitleDialog();
            }
        });
    }

    @Override
    public void initData() throws IOException {

    }


    private void inputTitleDialog() {

        final SuanFa suanFa = new SuanFa(ShareActivity.this);

        if (suanFa.getValue() == 0) {
            Toast.makeText(ShareActivity.this,"没有可以兑换的金额",Toast.LENGTH_SHORT).show();
            return;
        }

        final EditText inputServer = new EditText(this);
        inputServer.setFocusable(true);

        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(suanFa.getYuan())
                .setIcon(R.drawable.hongbao)
                .setView(inputServer).setNegativeButton("请输入密码", null);
        builder.setPositiveButton("确定",
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        String inputName = inputServer.getText().toString();
                        if (inputName.equals("201806")) {

                            suanFa.clear();

                        }
                        dialog.cancel();
                    }
                });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.show();
    }
}
